package com.my.zidingyikongjian.view.five;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

/**
 * 项目名称：drawText详解
 * 创建人：mwb
 * 创建时间：2018/7/17 9:35
 */

public class MyViewThree extends View {


    public MyViewThree(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public MyViewThree(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        int baseLineX = 0;
        int baseLineY = 200;

        // 画基线
        Paint paint = new Paint();
        paint.setColor(Color.RED);
        canvas.drawLine(baseLineX, baseLineY, 30000, baseLineY, paint);

        // 写文字
        paint.setColor(Color.GREEN);
        paint.setTextSize(120); // 像素
        paint.setTextAlign(Paint.Align.CENTER);
        canvas.drawText("A", baseLineX, baseLineY, paint);
    }
}
